<?php

namespace app\hospital\model;
use think\facade\Db;
use think\facade\Request;
use think\Model;
class subjecttype extends Model
{
    function del(){
        $id=Request::param('id');
        $da=Db::name('subjecttype')->where('id',$id)->select();
        dump($da['subjectid']);
//        $data=Db::name('doctor')->where('subjectid',$da['subjectid'])->select();

//        if($data->isEmpty()){
//            echo "该科室有约束";
//            return false;
//        }
//        else{
//            $res=Db::name('subjecttype')->where('id',$id)->delete();
//            return $res;
//        }
    }
    function search()
    {
        $key=Request::param('key');
        //  $data=Bookinfo::where("bookname","like","%".$key."%")->paginate(['list_rows'=>4,'query'=>Request::param()]);

        $data=subjecttype::withSearch(['subjectname'],[
            'subjectname'=>$key
        ])->paginate(['list_rows'=>3,'query'=>Request::param()]);
//        dump(Db::getlastsql());
        // halt($data->toArray());
        return $data;
    }

    function searchsubjectnameAttr($q,$v){
        //  halt($q,$v,$d);
        $q->where('subjectname','like','%'.$v.'%');

    }
}